﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Web
{
    public class ZPath
    {
        public static string MemberWebSite
        {
            get 
            {
                string url = RootAbsoluteURI;
                if(ZConfig.ReadAppSettings("IsUseMemberWebSite")=="true")
                {
                    url = RootAbsoluteURI.Replace("www","member");
                }
                return url;
            }
        }

        public static string DefaultWebSite
        {
            get
            {
                string url = RootAbsoluteURI;
                if (ZConfig.ReadAppSettings("IsUseMemberWebSite") == "true")
                {
                    url = RootAbsoluteURI.Replace("member", "www");
                }
                return url;
            }
        }

        public static string WebSite
        {
            get
            {
                if (System.Web.HttpContext.Current.Request.Url.Host.ToLower().IndexOf("member.") >= 0)
                {
                    return DefaultWebSite;
                }
                return RootAbsoluteURI;
            }
        }

        public static string VWebSite
        {
            get
            {
                if (System.Web.HttpContext.Current.Request.Url.Host.ToLower().IndexOf("member.") >= 0)
                {
                    return DefaultWebSite;
                }
                return RootVirtualURI;
            }
        }

        public static string RootAbsoluteURI
        {
            get
            {
                string host = string.Empty;
                if (System.Web.HttpContext.Current != null)
                {
                    host = "http://" + System.Web.HttpContext.Current.Request.Url.Host;
                    if (System.Web.HttpContext.Current.Request.Url.Port != 80)
                    {
                        host += ":" + System.Web.HttpContext.Current.Request.Url.Port.ToString();
                    }
                    if (RootVirtualURI != "/")
                        host += RootVirtualURI;
                    else
                        host += "/";
                }
                
                return host;
            }
        }
        public static string RootVirtualURI
        {
            get
            {
                string path = string.Empty;
                if (System.Web.HttpContext.Current != null)
                {
                    path = System.Web.HttpContext.Current.Request.ApplicationPath;
                    if (string.IsNullOrEmpty(path))
                        return "/";
                    if (!path.EndsWith("/"))
                        path = path + "/";
                }
                return path;
            }
        }

        private static string images
        {
            get
            {
                string url = "http://img2.lvshou.com/";
                if (!string.IsNullOrEmpty(ZConfig.ReadAppSettings("DefaultImagesURI")))
                {
                    url = ZConfig.ReadAppSettings("DefaultImagesURI");
                }
                return url;
            }
        }

        public static string RootURI { get { return RootAbsoluteURI; } }

        public static string ResourcesURI { get { return ResourcesAbsoluteURI; } }
        public static string ResourcesAbsoluteURI
        {
            get
            {
                if (ZConfig.IsUseImageHost)
                    return images;
                else
                    return ResourcesVirtualURI;
            }
        }
        public static string ResourcesVirtualURI { get { return RootVirtualURI + ZConfig.ResourcesDir + "/"; } }

        public static string ImagesURI { get { return ImagesAbsoluteURI; } }
        public static string ImagesAbsoluteURI { get { return ResourcesAbsoluteURI + "Images/"; } }
        public static string ImagesVirtualURI { get { return ResourcesVirtualURI + "Images/"; ; } }

        public static string StylesURI { get { return StylesAbsoluteURI; } }
        public static string StylesAbsoluteURI { get { return ResourcesAbsoluteURI + "Styles/"; } }
        public static string StylesVirtualURI { get { return ResourcesVirtualURI + "Styles/"; } }

        public static string ScriptsURI { get { return ScriptsAbsoluteURI; } }
        public static string ScriptsAbsoluteURI { get { return ResourcesAbsoluteURI + "Scripts/"; } }
        public static string ScriptsVirtualURI { get { return ResourcesVirtualURI + "Scripts/"; } }

        public static string TopicsURI
        {
            get
            {
                if (ZConfig.IsUseImageHost)
                    return TopicsAbsoluteURI;
                else
                    return TopicsVirtualURI;
            }
        }

        static int i = 1;

        public static string TopicsAbsoluteURI
        {
            get
            {
                string result = "http://img" + i.ToString() + ".lvshou.com/Topics/";
                if (i >= 3)
                    i = 1;
                else
                    i++;
                return result;
            }
        }

        public static string TopicsVirtualURI { get { return ResourcesVirtualURI + "Topics/"; } }

        public static string HTMLURI { get { return HTMLAbsoluteURI; } }
        public static string HTMLAbsoluteURI { get { return ResourcesAbsoluteURI + "HTML/"; } }
        public static string HTMLVirtualURI { get { return ResourcesVirtualURI + "HTML/"; } }



        public static string ADURI { get { return ADAbsoluteURI; } }
        public static string ADAbsoluteURI { get { return ResourcesAbsoluteURI + "GoodImages/"; } }
        public static string ADVirtualURI { get { return ResourcesVirtualURI + "GoodImages/"; } }

    }
}
